# -*- coding: utf-8 -*-
"""
author:码同学 极光
date:2025/3/15
desc: 
sample: 
"""

#获取files配置路径
import hashlib
import os

import openpyxl
import pandas as pd


def get_md5(data):
    md5 = hashlib.md5()
    md5.update(data.encode('utf-8'))
    return md5.hexdigest()

def get_project_path():
    """得到项目路径"""
    return os.path.dirname(__file__)

def get_files_path(file_name):
    """得到files配置路径"""
    return os.path.join(get_project_path(), 'files',file_name)


import time

def get_timestamp():
    return int(time.time() * 1000)


def read_excel_list(file_name,sheet=0,header=True):
    excel_sheet=[]
    file_path = get_files_path(file_name)
    workbook = openpyxl.load_workbook(file_path)
    worksheet = workbook.worksheets[sheet]
    if header:
        for row in worksheet.iter_rows(min_row=2):
            excel_sheet.append([cell.value for cell in row])
    else:
        for row in worksheet.iter_rows():
            excel_sheet.append([cell.value for cell in row])

    return excel_sheet


if __name__ == '__main__':
    print(read_excel_list('case.xlsx',header=False))
    test_data = {"username": ["user001", "user002", "user003"],
                 "age": [25, 30, 35],
                 "email": ["user1@example.com", "user2@example.com", "user3@example.com"]}
    df = pd.DataFrame(test_data)
    df.to_csv('test.csv')
    df.to_excel('test2.xlsx',index=False)



